package com.zhp.utils;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.security.MessageDigest;

/**
 * @date 2023/4/10
 * @desc
 */
public class MD5Util {

    public static String EncoderPwdByMd5(String str) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");

            BASE64Encoder encoder = new BASE64Encoder();

            return encoder.encode(md5.digest(str.getBytes("utf-8")));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

//    public static String DecodeMd5(String str) {
//        try {
//            MessageDigest md5 = MessageDigest.getInstance("MD5");
//            BASE64Decoder decoder = new BASE64Decoder();
//            return String.valueOf(md5.digest(decoder.decodeBuffer());
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }


    public static void main(String[] args) {

        String s = MD5Util.EncoderPwdByMd5("1");
        String s1 = MD5Util.EncoderPwdByMd5("123");

        System.out.println(s);
        System.out.println(s1);

//        System.out.println(MD5Util.DecodeMd5(s));

    }
}
